package com.mryang.hds.service.impl;

import com.mryang.hds.configs.AppException;
import com.mryang.hds.entity.Need;
import com.mryang.hds.mapper.NeedMapper;
import com.mryang.hds.service.INeedService;
import com.mryang.hds.utils.ResultCode;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Genius
 * @version 1.0.0
 * @ClassName NeedServiceImpl.java
 * @Description TODO
 * @createTime 2023年03月20日 12:28:00
 */

@Service
public class NeedServiceImpl implements INeedService {

    @Resource
    NeedMapper needMapper;

    @Override
    public void needSub(Need need) {
        try {
            needMapper.needSub(need);
        }catch (Exception e){
            throw new AppException(ResultCode.NEED_FAIL);
        }
    }

    @Override
    public List<Need> getNeedsByUId(Integer uid) {
        try {
            return needMapper.getNeedsByUId(uid);
        }catch (Exception e){
            throw new AppException(ResultCode.NEED_FAIL);
        }
    }

    @Override
    public void editNeedState(Integer needId) {
        try {
            needMapper.editNeedState(needId,2);
        }catch (Exception e){
            throw new AppException(ResultCode.NEED_FAIL);
        }
    }

    @Override
    public Need getOneNeedByUId(Integer loginId) {
        try {
            return needMapper.getOneNeedByUId(loginId);
        }catch (Exception e){
            throw new AppException(ResultCode.NEED_FAIL);
        }
    }

    @Override
    public void deleteNeed(Integer needId) {
        try {
            needMapper.deleteNeed(needId);
        }catch (Exception e){
            throw new AppException(ResultCode.NEED_FAIL);
        }
    }
}
